home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / msysjour / vol04 / 01b / macsl / mpmmap.c < prev    next >
C/C++ Source or Header  |  1988-10-03  |  6KB  |  199 lines

  1. /*-----------------------------------------------------------------*/
  2. /* MpmMap.c                                                        */
  3. /* Coordinate mapping functions                                    */
  4. /*-----------------------------------------------------------------*/
  5.  
  6. #include "MacPM.h"
  7.  
  8. /*-----------------------------------------------------------------*/
  9. /* Map a list of PM window points from hwndFrom's coordinates to   */
  10. /* hwndTo's coordinates.  cwpt is the number of points.            */
  11. /*-----------------------------------------------------------------*/
  12.  
  13. BOOL APIENTRY WinMapWindowPoints( hwndFrom, hwndTo, paptl, cwpt )
  14.     HWND        hwndFrom, hwndTo;
  15.     PPOINTL     paptl;
  16.     SHORT       cwpt;
  17. {
  18.     POINTL      ptlFrom, ptlTo;
  19.     PMYWND      pwnd;
  20.  
  21.     /* Fix up special case window handles */
  22.  
  23.     if( ! hwndFrom  ||  hwndFrom == HWND_DESKTOP )
  24.       hwndFrom = _hwndDesktop;
  25.  
  26.     if( ! hwndTo  ||  hwndTo == HWND_DESKTOP )
  27.       hwndTo = _hwndDesktop;
  28.  
  29.     if( ! MpmValidateWindow(hwndFrom)  ||
  30.         ! MpmValidateWindow(hwndTo) )
  31.       return FALSE;
  32.  
  33.     /* Get absolute positions for both windows */
  34.  
  35.     pwnd = PMYWNDOF(hwndFrom);
  36.     ptlFrom.x = pwnd->x;
  37.     ptlFrom.y = pwnd->y;
  38.     MpmMapAbsOfWin( pwnd->hwndParent, &ptlFrom, 1 );
  39.  
  40.     pwnd = PMYWNDOF(hwndTo);
  41.     ptlTo.x = pwnd->x;
  42.     ptlTo.y = pwnd->y;
  43.     MpmMapAbsOfWin( pwnd->hwndParent, &ptlTo, 1 );
  44.  
  45.     /* Adjust the points */
  46.  
  47.     for( ;  cwpt > 0;  paptl++, cwpt-- )
  48.     {
  49.       paptl->x += ptlFrom.x - ptlTo.x;
  50.       paptl->y += ptlFrom.y - ptlTo.y;
  51.     }
  52.  
  53.     return TRUE;
  54. }
  55.  
  56. /*-----------------------------------------------------------------*/
  57. /* Map a list of points from hwnd's coordinates to absolute        */
  58. /* coordinates.                                                    */
  59. /*-----------------------------------------------------------------*/
  60.  
  61. LOCAL VOID MpmMapAbsOfWin( hwnd, pptl, cwpt )
  62.     HWND        hwnd;
  63.     PPOINTL     pptl;
  64.     SHORT       cwpt;
  65. {
  66.     POINTL      ptlAdj;
  67.  
  68.     ptlAdj.x = ptlAdj.y = 0;
  69.  
  70.     for( ;  hwnd;  hwnd = MYWNDOF(hwnd).hwndParent )
  71.     {
  72.       ptlAdj.x += MYWNDOF(hwnd).x;
  73.       ptlAdj.y += MYWNDOF(hwnd).y;
  74.     }
  75.  
  76.     for( ;  cwpt > 0;  cwpt--, pptl++ )
  77.     {
  78.       pptl->x += ptlAdj.x;
  79.       pptl->y += ptlAdj.y;
  80.     }
  81. }
  82.  
  83. /*-----------------------------------------------------------------*/
  84. /* Map a PM POINTL to a Mac Point, using hwnd's coordinates.       */
  85. /*-----------------------------------------------------------------*/
  86.  
  87. LOCAL VOID MpmMapMacOfPtl( hwnd, ppoint, pptl )
  88.     HWND        hwnd;
  89.     Point*      ppoint;
  90.     PPOINTL     pptl;
  91. {
  92.     RECTL       rclMain;
  93.     HWND        hwndMain;
  94.     Rect*       prectAdj;
  95.     POINTL      ptl;
  96.  
  97.     ptl = *pptl;
  98.  
  99.     hwndMain = MAINHWND(hwnd);
  100.     prectAdj = &MYWNDOF(hwndMain).rectAdj;
  101.     WinQueryWindowRect( hwndMain, &rclMain );
  102.     WinMapWindowPoints( hwnd, hwndMain, &ptl, 1 );
  103.  
  104.     ppoint->h = ptl.x - prectAdj->left;
  105.     ppoint->v = rclMain.yTop - ptl.y - prectAdj->top;
  106. }
  107.  
  108. /*-----------------------------------------------------------------*/
  109. /* Map a PM RECTL to a Mac Rect, using hwnd's coordinates.         */
  110. /*-----------------------------------------------------------------*/
  111.  
  112. LOCAL VOID MpmMapMacOfRcl( hwnd, prect, prcl )
  113.     HWND        hwnd;
  114.     Rect*       prect;
  115.     PRECTL      prcl;
  116. {
  117.     RECTL       rclMain;
  118.     HWND        hwndMain;
  119.     Rect*       prectAdj;
  120.     RECTL       rcl;
  121.  
  122.     rcl = *prcl;
  123.  
  124.     hwndMain = MAINHWND(hwnd);
  125.     prectAdj = &MYWNDOF(hwndMain).rectAdj;
  126.     WinQueryWindowRect( hwndMain, &rclMain );
  127.     WinMapWindowRect( hwnd, hwndMain, &rcl );
  128.  
  129.     prect->left   = rcl.xLeft                  - prectAdj->left;
  130.     prect->right  = rcl.xRight                 - prectAdj->left;
  131.     prect->top    = rclMain.yTop - rcl.yTop    - prectAdj->top;
  132.     prect->bottom = rclMain.yTop - rcl.yBottom - prectAdj->top;
  133. }
  134.  
  135. /*-----------------------------------------------------------------*/
  136. /* Map a Mac Point to a PM POINTL, using hwnd's coordinates.       */
  137. /*-----------------------------------------------------------------*/
  138.  
  139. LOCAL VOID MpmMapPtlOfMac( hwnd, pptl, ppoint )
  140.     HWND        hwnd;
  141.     PPOINTL     pptl;
  142.     Point*      ppoint;
  143. {
  144.     Rect        rect;
  145.  
  146.     MpmQueryMacRect( hwnd, &rect );
  147.  
  148.     pptl->x = ppoint->h - rect.left;
  149.     pptl->y = rect.bottom - ppoint->v;
  150. }
  151.  
  152. /*-----------------------------------------------------------------*/
  153. /* Map a Mac Rect to a PM RECTL, using hwnd's coordinates.         */
  154. /*-----------------------------------------------------------------*/
  155.  
  156. LOCAL VOID MpmMapRclOfMac( hwnd, prcl, prect )
  157.     HWND        hwnd;
  158.     PRECTL      prcl;
  159.     Rect*       prect;
  160. {
  161.     Rect        rect;
  162.  
  163.     MpmQueryMacRect( hwnd, &rect );
  164.  
  165.     prcl->xLeft   = prect->left  - rect.left;
  166.     prcl->xRight  = prect->right - rect.left;
  167.     prcl->yBottom = rect.bottom  - prect->bottom;
  168.     prcl->yTop    = rect.bottom  - prect->top;
  169. }
  170.  
  171. /*-----------------------------------------------------------------*/
  172. /* Map a list of PM window points from absolute coordinates to     */
  173. /* hwnd's coordinates.                                             */
  174. /*-----------------------------------------------------------------*/
  175.  
  176. LOCAL VOID MpmMapWinOfAbs( hwnd, pptl, cwpt )
  177.     HWND        hwnd;
  178.     PPOINTL     pptl;
  179.     SHORT       cwpt;
  180. {
  181.     POINTL      ptlAdj;
  182.  
  183.     ptlAdj.x = ptlAdj.y = 0;
  184.  
  185.     for( ;  hwnd;  hwnd = MYWNDOF(hwnd).hwndParent )
  186.     {
  187.       ptlAdj.x -= MYWNDOF(hwnd).x;
  188.       ptlAdj.y -= MYWNDOF(hwnd).y;
  189.     }
  190.  
  191.     for( ;  cwpt > 0;  cwpt--, pptl++ )
  192.     {
  193.       pptl->x += ptlAdj.x;
  194.       pptl->y += ptlAdj.y;
  195.     }
  196. }
  197.  
  198. /*-----------------------------------------------------------------*/
  199.